# -*- coding: UTF-8 -*-

import os

from flask import Flask

from app.db import db
from app.ext import init_ext
from app.settings import envs


def create_app():
    app = Flask(__name__)
    env = os.environ.get('FLASK_APP_ENVIRON', 'develop')
    env = 'produce'
    if env not in ['develop', 'produce']:
        return ValueError('FLASK_APP_ENVIRON: %s ' % env)
    print('*************env:' + env)
    app.debug = True
    app.jinja_env.auto_reload = True
    app.config["SECRET_KEY"] = "123456"
    app.config.from_object(envs.get(env))
    print(app.config['SQLALCHEMY_DATABASE_URI'])
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    init_ext(app)

    # 文件上传
    app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024
    app.config['DROPZONE_ALLOWED_FILE_TYPE'] = 'image'
    print(app.url_map)
    return app
